/**
 *	流程模块主Flow操作记录
 *	开发者：雨中磐石
 *	地址：www.rockoa.com
 *	日期：2023-07-19
 */

package com.framework.Flow;



import com.framerock.baselib.CDate;
import com.framerock.baselib.Rock;
import com.framework.ACore.Model;

import java.util.ArrayList;
import java.util.Map;


public class FlowLog extends FlowBase {

    private Model modelLog;
    public FlowLog(Flow flows) {
        super(flows);
        this.modelLog = Model.get(flows.nDb, "flowlog");
    }

    /**
     * 添加操作记录
     * */
    public void addLog(String name, String sm, String params[])
    {
        Map<String,String> da = Rock.getMap(new String[]{
                "name", name,
                "explain", sm,
                "optdt", CDate.now(),
                "table",mFlow.table,
                "mid", mFlow.mid,
                "checkname", mRequest.getUserars("name"),
                "checkid",mRequest.USEAID,
                "cid", mRequest.COMPANYID,
                "modeid", mFlow.modeid
        });
        if(params!=null){
            int len = params.length;
            for(int i=0;i< len-1;i=i+2){
                da.put(params[i], params[i+1]);
            }
        }
        this.modelLog.insertbo(da);
    }

    /**
     * 获取记录
     * */
    public ArrayList<Map<String, String>> getLog()
    {
        ArrayList<Map<String, String>> rows = this.modelLog.getAll(mFlow.mwhere, "*", "id asc");
        return rows;
    }

    /**
     * 操作记录统计
     * */
    public int getLogcount()
    {
        return this.modelLog.getCount(mFlow.mwhere);
    }

    /**
     * 审批的操作记录
     * */
    public ArrayList<Map<String, String>> getCourseLog()
    {
        ArrayList<Map<String, String>> rows = this.modelLog.getAll(mFlow.mwhere+" AND `courseid`<>0 AND `valid`=1", "*", "id asc");
        return rows;
    }
}
